package com.bjpowernode.crm.setting.service.impl;

import com.bjpowernode.crm.setting.dao.DicTypeDao;
import com.bjpowernode.crm.setting.dao.DicValueDao;
import com.bjpowernode.crm.setting.eneity.DicValue;
import com.bjpowernode.crm.setting.service.DicService;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DicServiceImpl implements DicService {
    private DicValueDao valueDao;
    private DicTypeDao typeDao;

    public void setValueDao(DicValueDao valueDao) {
        this.valueDao = valueDao;
    }

    public void setTypeDao(DicTypeDao typeDao) {
        this.typeDao = typeDao;
    }

    //调用dao查询数据字典
    @Override
    @Transactional
    public Map<String, List<DicValue>> getAll() {
        //查询所有的type值
        List<String> typeNameList=typeDao.queryType();
        //再根据所有的type进行分组查询各个类型对应的字典值
        Map<String, List<DicValue>> map=new HashMap<>();
        for (int i=0;i<typeNameList.size();i++){
            String keyName=typeNameList.get(i);
            List<DicValue> valueList=valueDao.queryValues(typeNameList.get(i));
            map.put(keyName,valueList);
        }
        return map;
    }
}
